<?php

class m111206_074019_company_certificate extends CDbMigration {
	public function safeUp() {
		$this
			->createTable('erp_company_certificate',
				array(
					'id' => 'pk',
					'name' => 'string',
					'grantDate' => 'date',
					'verifyDate' => 'date',
					'extendDate' => 'date',
					'expireDate' => 'date',
					'previewImage' => 'string',
					'previewThumb' => 'string',
					'note' => 'text',
					'createTime' => 'datetime',
					'createUserId' => 'int',
					'updateTime' => 'datetime',
					'updateUserId' => 'int',
				));
		$this
			->createIndex("company_certificate_create_user_id", 'erp_company_certificate',
				'createUserId');
		$this
			->addForeignKey('fk_company_certificate_create_user_id', 'erp_company_certificate',
				'createUserId', 'erp_user', 'id', 'SET NULL', 'CASCADE');
		$this
			->createIndex("company_certificate_update_user_id", 'erp_company_certificate',
				'updateUserId');
		$this
			->addForeignKey('fk_company_certificate_update_user_id', 'erp_company_certificate',
				'updateUserId', 'erp_user', 'id', 'SET NULL', 'CASCADE');
		
		$this->addColumn('erp_employee_certificate', 'educateDate', 'date');
		$this->addColumn('erp_employee_certificate', 'extendDate', 'date');
		$this->addColumn('erp_employee_certificate', 'expireDate', 'date');
	}

	public function safeDown() {
		$this->dropTable('erp_company_certificate');
		$this->dropColumn('erp_employee_certificate', 'educateDate');
		$this->dropColumn('erp_employee_certificate', 'extendDate');
		$this->dropColumn('erp_employee_certificate', 'expireDate');		
	}
}
